package com.xidian.zhiancloud.controller.systemset;

import com.xidian.zhiancloud.controller.base.BaseController;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.model.syset.UserCertificate;
import com.xidian.zhiancloud.service.user.UserCertificateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户-证书
 */
@RestController
@RequestMapping("/usercerti")
public class UserCertificateController extends BaseController {

    @Autowired
    UserCertificateService userCertificateService;

    /**
     * 用户证书列表
     * @return
     */
    @RequestMapping("/getUserCertificateList")
    public ResultDTO getUserCertificateList(){
        Long companyId = this.getSessionUserCompanyId();
        Long userId = this.getSessionUserid();
        List<UserCertificate> userCertList = userCertificateService.
            getUserCertificateList(companyId,userId);
        return ResultDTO.successOf(userCertList , GeneralResponseEnums.SUCCESS);
    }

    @RequestMapping("/addUserCertificate")
    public ResultDTO addUserCertificate(@RequestParam("userId") String userId,UserCertificate userCert){
        Map<String,Object> in = new HashMap<String, Object>();
            in.put("companyId", this.getSessionUserCompanyId());
            in.put("userId", userId);
            in.put("certificateName", userCert.getCertificateName());
            in.put("certificateNumber",userCert.getCertificateNumber());
            in.put("certifyingAuthority",userCert.getCertifyingAuthority());
            in.put("periodValidity", userCert.getPeriodValidity());
            in.put("reviewDate",userCert.getReviewDate());
            in.put("certificatePhotos", userCert.getCertificatePhotos());
            in.put("createId", this.getSessionUserid());
        userCertificateService.addUserCertificate(in);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    @RequestMapping("/updateUserCertificate")
    public ResultDTO updateUserCertificate(@RequestParam("id") String id,UserCertificate userCert){
        Map<String,Object> in = new HashMap<String, Object>();
        in.put("certificateName", userCert.getCertificateName());
        in.put("certificateNumber",userCert.getCertificateNumber());
        in.put("certifyingAuthority",userCert.getCertifyingAuthority());
        in.put("periodValidity", userCert.getPeriodValidity());
        in.put("reviewDate",userCert.getReviewDate());
        in.put("certificatePhotos", userCert.getCertificatePhotos());
        userCertificateService.updateUserCertificate(id,in);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }

    @RequestMapping("/deleteUserCertificate")
    public ResultDTO deleteUserCertificate(@RequestParam("id") String id){
        userCertificateService.deleteUserCertificate(id);
        return ResultDTO.successOf(GeneralResponseEnums.SUCCESS);
    }
    
}
